package cn.sharp.bbs.dao;

import cn.sharp.bbs.entity.DO.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

//TODO: SQL

/**
 * @author zhao yu
 */
@Mapper
public interface FlowDao {

    List<PostDto> getFlow(int area, int type, int label);

    List<Label> getLabel(Long postId);

    PostDto getVersion(Long postId);

    @Select("select count(*) from t_like where user_id = #{userId} and post_id = #{postId}")
    int ifLike(Long userId, Long postId);

    @Select("select count(*) from t_collect_post where user_id = #{userId} and post_id = #{postId}")
    int ifCollect(Long userId, Long postId);

    @Select("select count(*) from t_follow_post where user_id = #{userId} and post_id = #{postId}")
    int ifFollowPost(Long userId, Long postId);

    @Select("select count(*) from t_follow_user where user_id = #{userId} and user_followed = #{authorId}")
    int ifFollowAuthor(Long userId, Long authorId);

    @Select("select count(*) from t_like where post_id = #{postId}")
    Long likeCount(Long postId);

    @Select("select count(*) from t_collect_post where post_id = #{postId}")
    Long collectCount(Long postId);

    @Select("select count(*) from t_follow_post where post_id = #{postId}")
    Long followPostCount(Long postId);

    List<BrowseRecord> getBrowseRecordList();

    @Delete("delete from t_personalized where 1=1")
    void deleteAll();

    @Insert("insert into t_personalized(user_id, post_id) values (#{userId}, #{postId})")
    void insertPersonalized(Long userId, Long postId);

    List<PostDto> getPersonalized(Long userId);

    PostDto getPostImg(Long postId);

    @Select("select post_id as postId, post_hour as hour from t_post")
    List<Score> getPostPassTime();

    @Update("update t_post set post_hour = #{i}, post_score = #{score} where post_id = #{postId}")
    void updateHour(Long postId, int i, double score);

    List<PostDto> getHottest();

    List<PostDto> getLatest();

    List<PostDto> getFollow(Long u_id);
}
